package br.com.rookgraph.heuristica;

import br.com.rookgraph.Edge;


public class Plus implements Heuristica {

	@Override
	public Edge selectForCut(Edge candidate, Edge edgeCut) {

		Edge edgeSelect = edgeCut;

		if (edgeSelect == null || candidate.beta < edgeSelect.beta) {
			edgeSelect = candidate;

		} else if (candidate.beta == edgeSelect.beta) {
			if (candidate.gama < edgeSelect.gama) {
				edgeSelect = candidate;

			}else if (candidate.gama == edgeSelect.gama){
				
				if( candidate.sigma < edgeSelect.sigma){
					edgeSelect = candidate;

				}else if( candidate.sigma == edgeSelect.sigma){

					if( candidate.sigmaLine > edgeSelect.sigmaLine){
						edgeSelect = candidate;
					}
				}
			}
		}

		return edgeSelect;
	}

	@Override
	public Edge selectForRep(Edge candidate, Edge edgeRep) {

		if (edgeRep == null || Math.abs(candidate.beta) < Math.abs(edgeRep.beta)) {
		//	if (edgeRep == null || (candidate.beta) < (edgeRep.beta)) {
			edgeRep = candidate;
		}
		else if (candidate.beta == edgeRep.beta) {
			if (candidate.gama < edgeRep.gama) {
				edgeRep = candidate;

			}else if (candidate.gama == edgeRep.gama){

				if (candidate.sigma > edgeRep.sigma){
					edgeRep = candidate;
									
				}else if( candidate.sigma == edgeRep.sigma){

					if( candidate.sigmaLine < edgeRep.sigmaLine){
						edgeRep = candidate;
					}
				}
			}
		}
		return edgeRep;
	}

	/* (non-Javadoc)
	 * @see br.com.rookgraph.heuristica.Heuristica#isVantajoso(br.com.rookgraph.Edge, br.com.rookgraph.Edge)
	 *
	 * Esse metodo pode ser melhorado chamando um dos acima
	 * -TODO verifica isso
	 *
	 */
	@Override
	public boolean isVantajoso(Edge edgeRep, Edge edgeCut) {

		Edge vantajosa = selectForRep(edgeRep, edgeCut);
	return vantajosa == edgeRep;
	}

}
